
class Solution {
public:
    void duplicateZeros(vector<int>& arr) {
        int len = arr.size();
        int cur = 0;
        int des = -1;
        if (len == 1)
        {
            return;
        }
        while (1)
        {
            if (arr[cur] == 0)
            {
                des += 2;
            }
            else
            {
                des += 1;
            }
            cur++;
            if (des == len - 1)
            {
                cur--;
                break;
            }
            else if (des == len)
            {
                cur -= 2;
                des--;
                arr[des] = 0;
                des--;
                break;

            }

        }
        while (cur >= 0)
        {
            if (arr[cur] != 0)
            {
                arr[des] = arr[cur];
                cur--;
                des--;
            }
            else if (arr[cur] == 0)
            {
                arr[des] = 0;
                des--;
                arr[des] = 0;
                cur--;
                des--;
            }
        }
    }
};